﻿#ifndef DB_H
#define DB_H

//#include <QtSql\qsqldatabase.h>
//#include <QtSql\qsqlquery.h>
#include <qdatetime.h>
#include <qlist.h>
#include<qsqldatabase.h>
#include<qsqlquery.h>
// DataBase
class GYSCADALogItem
{
public:
    int         userId;
    QString     operation;
    QString     result;
    QString     equipment;
    QDateTime   timestamp;
}
;
class GYSCADADB
{
public:
    static GYSCADADB* getInstance();

protected:
    GYSCADADB();
    ~GYSCADADB();

public:
    bool isOpen();
    QString lastError();
    bool verify(const QString& userName, const QString& password);
    QString getStafferName(const QString& userName, const QString& password);
    int getUserId(const QString& userName, const QString& password);
    bool record(QList<GYSCADALogItem>& items);

private:
    bool getQueryResult(QSqlQuery& query);
    bool getQueryResult(QSqlQuery& query, QString& result);
    bool getQueryResult(QSqlQuery& query, int& result);

private:
    static GYSCADADB* instance;

private:
    QSqlDatabase db;
};

#endif /* DB_H */
